﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;

namespace MicroTest
{
    class SerializeHelper
    {
        public static bool SerialData(string fileName,object objtoSerial)
        {

            Stream fStream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite);
            BinaryFormatter binFormat = new BinaryFormatter();//创建二进制序列化器
            binFormat.Serialize(fStream, objtoSerial);
            fStream.Close();
            return true;
        }
        public static T DeserialData<T>(string fileName)
        {
            FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
            BinaryFormatter b = new BinaryFormatter();
            T obj = (T)b.Deserialize(fileStream);
            fileStream.Close();
            return obj;

        }
    }
}
